package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.AnswerAskViewAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.EmptyRecyclerView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.AnswerAskBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetMyAnswerListModel;

public class UserAnswerActivity extends BaseActivity {
    EmptyRecyclerView useranswer_rv;
    View useranswer_emptyview;

    ImageView useranswer_fh;
    private List<AnswerAskBean> items;
    private boolean up = false;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_user_answer);
        useranswer_rv = (EmptyRecyclerView)findViewById(R.id.useranswer_rv);
        useranswer_fh = (ImageView)findViewById(R.id.useranswer_fh);
        useranswer_emptyview = (View)findViewById(R.id.useranswer_emptyview);

        GetMyAnswerListModel getMyAnswerListModel = new GetMyAnswerListModel();
        getMyAnswerListModel.getMyAnswerList(getid(), new ListListener<AnswerAskBean>() {
            @Override
            public void onResponse(List<AnswerAskBean> list) {
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(UserAnswerActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                useranswer_rv.setLayoutManager(linearLayoutManager);
                items=list;
                AnswerAskViewAdapter answerAskViewAdapter=new AnswerAskViewAdapter(UserAnswerActivity.this,items,R.layout.answer_ask_item);
                useranswer_rv.setAdapter(answerAskViewAdapter);
                useranswer_rv.setItemAnimator(new DefaultItemAnimator());
                useranswer_rv.setEmptyView(useranswer_emptyview);
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    void initEvent() {
        useranswer_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    void initDate() {

    }
    @Override
    protected void onPause() {
        super.onPause();
        up = true;

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (up) {
            initView();
            initEvent();
            initDate();
            up = false;
        }
    }
}
